﻿<%@ Page Title="" Language="C#" MasterPageFile="~/edit/Admin.Master" AutoEventWireup="true" CodeBehind="LocationList.aspx.cs" Inherits="ChgDoc.Edit.LocationList" %>
<asp:Content ID="header" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
    $(document).ready(function () {
        $('.articleLocation').sortable({
            stop: function (evt, ui) {
                var locId = $(ui.item).parent().attr('data-bind-locationid');

                var items = $(ui.item).parent().children();

                var articleIds = "[";
                for (var idx = 0; idx < items.length; idx++) {
                    articleIds += $(items[idx]).attr('data-bind-articleid');
                    if (idx + 1 < items.length)
                        articleIds += ", ";
                }
                articleIds += "]";

                var submitData = '{ locationId : "' + locId + '", articles: ' + articleIds + '}';
                doAjax(appGlobal.serverUrl + 'service/article.asmx/SortLocationOrder', submitData);


            }
        });
        $('.articleLocation').disableSelection();
    });
</script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="pageContent" runat="server">
    <div class="formStyle">
        
        <div style="padding: 20px;">
        <asp:Repeater ID="rptLocation" runat="server" OnItemDataBound="rptLocation_ItemDataBound">
            <HeaderTemplate><ul class="sortable-header"></HeaderTemplate>
            <ItemTemplate><li><%# Eval("Name") %>
                <ul class="articleLocation" data-bind-locationid='<%# Eval("Id") %>' >
                    <asp:Repeater ID="rptLocationArticle" runat="server">
                        <ItemTemplate><li  data-bind-articleid="<%# Eval("ArticleId") %>"><div class="ui-icon ui-icon-arrowthick-2-n-s" style="float:left;"></div><%# Eval("Title") %></li></ItemTemplate>
                    </asp:Repeater>
                </ul>
            </li></ItemTemplate>
            <FooterTemplate></ul></FooterTemplate>
        </asp:Repeater>
        </div>

	    <asp:datagrid id="grdList" runat="server" autogeneratecolumns="False" CssClass="grid" OnItemCommand="grdList_ItemCommand" OnEditCommand="grdList_Edit" OnCancelCommand="grdList_Cancel" OnUpdateCommand="grdList_Update" >
	    <HeaderStyle CssClass="gridHeader" />
	    <columns>
		    <asp:BoundColumn DataField="Id" visible="false" readonly="true" />
            <asp:BoundColumn DataField="Code" visible="true" HeaderText="Code" />            
            <asp:BoundColumn DataField="Name" visible="true" HeaderText="Name" />          
            <asp:ButtonColumn ButtonType="Linkbutton" CommandName="Articles" Text="Articles" />  
            <asp:EditCommandColumn ButtonType="LinkButton" EditText="Edit" CancelText="Cancel" UpdateText="Save" />
		    <asp:ButtonColumn ButtonType="Linkbutton" CommandName="Delete" Text="Delete" />
	    </columns>
	    </asp:datagrid>

        <br />
        
        <table cellspacing="0" cellpadding="0" class="std">
            <tr class="head"><td colspan="2"><h5>New Location</h5></td></tr>
            <tr class="gray"><td class="lbl">Code</td><td><asp:textbox id="txtCode" runat="server" class="txtbox" /></td></tr>
            <tr class="gray"><td class="lbl">Name</td><td><asp:TextBox ID="txtName" runat="server" class="txtbox" /></td></tr>
            <tr><td></td><td ><asp:Button ID="btnAdd" Text="save" OnClick="btnAdd_click" runat="server" class="ui-state-default" /></td></tr>
        </table>
	
        
    </div>

</asp:Content>
